(function (G) {
    const javaUrl = G.Storage.get('JAVAURL')
    G.vue({
        data: {
           
            markers: [], // 所有标记点
            latitude: '29.50207', // 当前纬度
            longitude: '106.5114', // 当前经度
            pageType: 'user',
            userList: [],
            rightNav: [{
                    url: 'person_noSelect.png',
                    selectUrl: 'person_select.png',
                    isSelect: true
                },
                {
                    url:'car_no_select.png',
                    selectUrl: 'car_select.png',
                    isSelect: false
                },
                {
                    url:'cleaner_no_select.png',
                    selectUrl: 'cleaner_select.png',
                    isSelect: false
                },
            ],
            
            type:'1',//1巡查人员 2清洁  3车辆
            isMore: true,
            page: 1,
            id: '',
            triggered: false,
        },
        methods: {
            // markerInfo(event){
            //     let item = this.data.userList[event.markerId]
            //     G.toask(`${item.userName}\r\n${item.createTimeString}\r\n${item.locationDetail}`)
            // },
            // 获取人员列表
            getPersonList() {
                const {type,userList} = this.data
                G.get(javaUrl + '/clock/getpageAll', {
                    pageSize: 1000,
                    pageNum: 1,
                    clockType:type
                }).then(rej => {
                    console.log(rej, '拿到数据')
                    let list = (rej && rej.rows) || []
                    let param = []
                    const imgObj = {
                        1:'/images/patrol.png',
                        2:'/images/location.png',
                        3:'/images/car.png'
                    }
                    list.forEach((item,index)=>{
                        let checkinTime = item.checkinTime + '000'
                        item.onlineString = new Date().getTime() - checkinTime < 2 * 60 * 60 * 1000 ? '近两小时在线' : G.date(checkinTime).Format('yyyy-MM-dd hh:mm:ss')
                        item.online = new Date().getTime() - checkinTime < 2 * 60 * 60 * 1000 ? 1 : 0
                        param.push({
                            // 'callout': {
                            //     // 'content': `${item.userName}\r\t${item.createTimeString}\r\t${item.locationDetail}`,
                            //     'content':item.userName,
                            //     'color': 'red'
                            // },
                            title:item.userName,
                            latitude:item.lat/1000000,
                            longitude:item.lng/1000000,
                            alpha:item.online ? 1 : 0.2,
                            // 'iconPath': imgObj[type],
                            'id': index,
                            'width': '25',
                            'height': '25'
                        })
                    })
                    
                   console.log(param,'paramparam')
           
                    let isMore = true
                    if (list.length < 10) isMore = false
                    list = [...userList, ...list]
                    list.sort((a,b) => b.id - a.id)
                    // list.sort((a,b) => b.online - a.online)
                    this.setData({
                        userList: list,
                        isMore:isMore,
                        triggered: false,
                        markers: param
                    })
                })
            },
            toDetail(e) {
                const {
                    id
                } = e.currentTarget.dataset
                wx.navigateTo({
                  url: '/pages/clockIn/mapDetail/index?id='+id + '&type=' + this.data.type,
                })
            },
            navTab (e){
                const {index } = e.currentTarget.dataset
                const {rightNav} = this.data
                let newList = JSON.parse(JSON.stringify(rightNav))
                newList[index].isSelect = true
               
                const typeObj = {
                    0:'1',//巡查员
                    1:'3',//车辆
                    2:'2',//清洁工
                }
                newList.forEach((item,index2)=>{
                    if (index2!=index) item.isSelect = false
                })
                this.setData({
                    rightNav:newList,
                    userList:[],
                    type:typeObj[index]
                })
                this.getPersonList()
            },
         
            onShow(e) {
                this.setData({
                    timeController: true
                })
            },
            onHide() {
                this.setData({
                    timeController: false
                })
            },
            refresherpulling(e) {
                console.log('下拉刷新', e)
                if (e.detail.dy < 10) return
                this.setData({
                    triggered: true,
                    userList: [],
                    page: 1
                })
                this.getPersonList()
            },
            scrolltolower() {
                const { page, isMore} = this.data
                let pageNum = page + 1
                if (isMore) {
                    this.setData({
                        page: pageNum
                    })
                    this.getPersonList()
                }

            }
        },
        mounted() {
            this.getPersonList()
        }
    })
})(wx.$)